﻿using System;
using System.Linq;
using IceTodo.DataStore.Enums;
using IceZero.DataStore.Models;
using IceZero.DataStore.Models.Enums;
using NHibernate.Criterion;

namespace IceZero.DataStore.InitDB
{
    /// <summary>
    /// 数据库初始化器
    /// </summary>
    public partial class DbInitializer
    {

        public DbInitializer Initialize()
        {
            InitAppConfig();
            //InitPrimaryKeyModeModels();
            InitCat();
            InitStatisticModels();
            return this;
        }
        
        public DbInitializer UpdateV1_0_0_1()
        {
            if (!AppConfigUpdateV1_0_0_1()) { return this; }

            return this;
        }

        /*
        public void InitDBConfig()
        {
            NHibernateHelper.UseSessionWithTransaction(session =>
            {
                session.Save(new DBConfig()
                {
                    Id = 1,
                    Key = "project_name",
                    Value = "IceTodo",
                    Remark = "项目名称"
                });
            });
        }
        public void InitTodoUser()
        {
            var adminId = IceTodoGlobalInfo.AdminId;

            ManagerProvider.TodoUserManager.Save(new TodoUser()
            {
                Guid = IceTodoGlobalInfo.AdminGuid,
                Account = "Admin",
                Password = "123456",
                Nickname = "超级管理员",
                CreateTime = DateTime.Now,
                UpdateTime = DateTime.Now,
                Salt = "0",
                CreatorId = adminId,
                UpdaterId = adminId
            });
            ManagerProvider.TodoUserDetailManager.Save(new TodoUserDetail()
            {
                Id = adminId,
                Country = "中国",
                Email = "123456@example.com",
                MobilePhone = "19941111111",
                Remark = "超管账号，谨慎保管密码"
            });
        }
        public void InitTodoLabel()
        {
            var adminId = IceTodoGlobalInfo.AdminId;
            ManagerProvider.TodoLabelManager.Save(new TodoLabel()
            {
                Guid = Guid.NewGuid().ToString("N").ToString(),
                Name = "普通",
                Type = LabelType.Priority,
                CreatorId = adminId,
                UpdaterId = adminId
            });
            ManagerProvider.TodoLabelManager.Save(new TodoLabel()
            {
                Guid = Guid.NewGuid().ToString("N").ToString(),
                Name = "重要",
                Type = LabelType.Priority,
                CreatorId = adminId,
                UpdaterId = adminId
            });
            ManagerProvider.TodoLabelManager.Save(new TodoLabel()
            {
                Guid = Guid.NewGuid().ToString("N").ToString(),
                Name = "非常重要",
                Type = LabelType.Priority,
                CreatorId = adminId,
                UpdaterId = adminId
            });
            ManagerProvider.TodoLabelManager.Save(new TodoLabel()
            {
                Guid = Guid.NewGuid().ToString("N").ToString(),
                Name = "红色",
                Type = LabelType.Color,
                CreatorId = adminId,
                UpdaterId = adminId
            });
            ManagerProvider.TodoLabelManager.Save(new TodoLabel()
            {
                Guid = Guid.NewGuid().ToString("N").ToString(),
                Name = "绿色",
                Type = LabelType.Color,
                CreatorId = adminId,
                UpdaterId = adminId
            });
        }
        
        public void InitTodoContent()
        {
            var adminId = IceTodoGlobalInfo.AdminId;
            ManagerProvider.TodoContentManager.Save(new TodoContent()
            {
                Guid = Guid.NewGuid().ToString("N").ToString(),
                CreatorId = adminId,
                UpdaterId = adminId,
                Title = "Hello World",
                Content = "this is the default content",
                IsCompleted = false
            });
        }
        */
    }
}
